define(function(require){
	var $=require("jq");
	/**
	*@上传删除图片控件
	*@2014-03-04
	*@杨永
	*/
	function UploadImage(uploadArea,waitingForm){
		//uploadAreaList(这个参数是上传图片区域)
		//waitingIframe(这个参数是等待提交的隐藏框架)
		var _this_=this;
		//保存上传区域
		this.uploadImg=uploadArea;
		this.isShow = this.uploadImg.attr("data-btn-show")||"hide";
		//保存上的列表
		this.uploadImgListsBox=this.uploadImg.find("li");
		if(this.isShow === "show"){
			this.uploadImgListsBox.find("span").show();
		};
		//保存等待上传的iframe
		this.waitingForm=waitingForm;
		//保存上传按钮列表
		this.uploadBtns=uploadArea.find("a.upload-btn");
		this.delBtns=uploadArea.find("a.del-btn");
		//保存隐藏的file->input
		this.hideFileInput=waitingForm.find("input[type=file]");
		this.uploadBtns.click(function(){
			//每次点击的时候就触发隐藏的input->file
			_this_.hideFileInput.attr("name",$(this).attr("data-series")).click();
		});
		//绑定onchang事件
		_this_.hideFileInput.change(function(){
			_this_._submitHideForm();
		});
		//删除图片
		this.delBtns.click(function(){
			_this_._delImage(this);
		});
		if(this.isShow !== "show"){
			//绑定移入移出功能
			this.uploadImgListsBox.hover(function(){
				$(this).find("span").stop().slideDown("fast");
			},function(){
				$(this).find("span").stop().slideUp("fast");
			});
		};
		
	};
	UploadImage.prototype={
		//删除图片
		_delImage:function(thisObj){
			var src = $(thisObj).parent().prev().eq(0).attr("data-src");
			$.get("/userCenter/deleteCustomerServiceImage.do",{src:src},function(ret){
				
				
			});
			$(thisObj).parent().prev().get(0).removeAttribute("src");
			//alert($(thisObj).attr("data-series"));
		},
		//提交隐藏file
		_submitHideForm:function(){
			this.waitingForm.submit();
		}
	};
	//创建上传控件
	$(function(){var uploadImage=new UploadImage($("div.upload-wrapper"),$("#uploadImageData"));});
});